<script setup>
import { ref } from "vue";
import { registerApi } from "../../../api/auth";

const formData = ref({
  username: "",
  password: "",
});

const submit = async () => {
  try {
    await registerApi(formData.value);
    uni.reLaunch({ url: "/pages/auth/index" });
  } catch (error) {
    console.log(error);
  }
};
</script>

<template>
  <view class="login">
    <view class="login-container">
      <uni-forms>
        <uni-forms-item label="用户名" prop="username" required>
          <uni-easyinput
            v-model="formData.username"
            placeholder="请输入用户名"
          />
        </uni-forms-item>
        <uni-forms-item label="密码" prop="password" required>
          <uni-easyinput
            v-model="formData.password"
            placeholder="请输入密码"
            type="password"
          />
        </uni-forms-item>

        <view class="uni-button-group">
          <button type="primary" @click="submit">注册</button>
        </view>
      </uni-forms>
    </view>
  </view>
</template>
